package svc

import (
	"github.com/bwmarrin/snowflake"
	_ "github.com/lib/pq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"xialou_platform/services/wallet/model"
	"xialou_platform/services/wallet/rpc/internal/config"
)

type ServiceContext struct {
	Config                config.Config
	Flake                 *snowflake.Node
	WalletModel           model.WalletModel
	WalletLogModel        model.WalletLogModel
	WalletWithdrawalModel model.WalletWithdrawalModel
	BankIconModel         model.BankIconModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn("postgres", c.Postgres.DataSource)
	flake, err := snowflake.NewNode(c.SnowflakeNode)
	if err != nil {
		panic(err)
	}
	return &ServiceContext{
		Config:                c,
		Flake:                 flake,
		WalletModel:           model.NewWalletModel(conn, c.CacheRedis),
		WalletLogModel:        model.NewWalletLogModel(conn, c.CacheRedis),
		WalletWithdrawalModel: model.NewWalletWithdrawalModel(conn, c.CacheRedis),
		BankIconModel:         model.NewBankIconModel(conn, c.CacheRedis),
	}
}
